import java.io.*;
import java.net.*;

public class RaxiPommitusServer{
	public static void main(String[] arg) throws Exception{
		ServerSocket ss=new ServerSocket(4407);
		Socket sc1=ss.accept();
		PrintWriter vorku1=new PrintWriter(sc1.getOutputStream(), true);
		BufferedReader br1=new BufferedReader(new InputStreamReader(sc1.getInputStream()));
		vorku1.println("Tere tulemast! Oota paarilist! Nii kaua joonista paberile laevad!");
		Socket sc2=ss.accept();
		PrintWriter vorku2=new PrintWriter(sc2.getOutputStream(), true);
		BufferedReader br2=new BufferedReader(new InputStreamReader(sc2.getInputStream()));
		vorku2.println("Tere tulemast! Joonista paberile laevad!");	
		vorku1.println("Paariline olemas! Vajuta enter, kui laevad valmis. Oota vastase kinnitust...");
		br1.readLine();
		vorku2.println("Paarilisel laevad valmis! Kui sul ka, vajuta enter...");
		br2.readLine();
		while(true){
			while(br1.ready()){br1.readLine();} //tyhjendab puhvri
			vorku1.println("paku");
			String rida=br1.readLine();
			while(br2.ready()){br2.readLine();}
			vorku2.println("Pakuti "+rida+". Vasta 'pihtas' v6i paku ise.");
			rida=br2.readLine();
			vorku1.println("Pakuti "+rida);
		}
	}
}